<template>
  <!-- 添加或修改盘点计划对话框 -->
  <el-dialog :title="title" v-if="open" v-model="open" width="600px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="90px" style="padding-left: 10%" v-loading="loading">
      <el-form-item label="跟单类型:" prop="followTypeId">
        <el-select v-model="form.followTypeId" placeholder="请选择跟单类型" clearable>
          <el-option v-for="item in followTypeList" :key="item.id" :label="item.typeName" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="阶段过程:" prop="stageProcess" >
        <el-select v-model="form.stageProcess" placeholder="请选择阶段过程" clearable>
          <el-option label="合同" value="1" />
          <el-option label="开票" value="2" />
          <el-option label="收款" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="阶段名称:" prop="name">
        <el-input v-model="form.name" placeholder="请输入阶段名称"></el-input>
      </el-form-item>
      <el-form-item label="进度系数:" prop="progressCoefficient">
        <el-input v-model="form.progressCoefficient" placeholder="请输入百分%"></el-input>
      </el-form-item>
      <el-form-item label="阶段周期:" prop="stageCycle">
        <el-input-number v-model="form.stageCycle" placeholder="请输入"></el-input-number>
      </el-form-item>
      <el-form-item label="跟单状态:" prop="stageName">
        <el-select v-model="form.stageName" placeholder="请选择跟单状态">
          <el-option v-for="item in follow_stage" :key="item.id" :label="item.followStatusName" :value="item.id + ''" />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态:" prop="status">
        <el-switch v-model="form.status" active-value="1" inactive-value="0"></el-switch>
      </el-form-item>
      <el-form-item label="审核人:" prop="auditUserId" v-if="form.status == 1">
        <el-select v-model="form.auditUserId" filterable clearable remote reserve-keyword placeholder="请选择审核人">
          <el-option v-for="item in userList" :key="item.value" :label="item.nickName" :value="item.userId" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="排序:" prop="sort">
        <el-input v-model="form.sort"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="备注:" prop="remark">
        <el-input v-model="form.remark"></el-input>
      </el-form-item> -->
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm" :loading="loading">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import followStage from '@/api/goods/followStage';
import modelMixin from '@/mixins/modelMixin';
import { listUser } from '@/api/system/user';
import { listFollowType } from '@/api/goods/followType';
export default {
  name: 'addForm',
  mixins: [modelMixin],
  data() {
    return {
      funcObj: followStage, //方法对象
      id: null, //必须配置，编辑需要赋值
      open: false,
      title: '添加跟单阶段',
      form: {
        stageName: '',
        auditUserId: '',
        remark: '',
        typeCategory:1
      },
      userList: [],
      follow_stage: [],
      followTypeList: [],
      rules: {
        name: [{ required: true, message: '阶段名称不能为空', trigger: 'blur' }],
        stageName: [{ required: true, message: '跟单名称不能为空', trigger: 'blur' }],
        followTypeId: [{ required: true, message: '请选择跟单类型', trigger: 'change' }],
        progressCoefficient: [
          { required: true, message: '进度系数不能为空', trigger: 'blur' },
          { pattern: /^(100|[1-9]\d|\d)(.\d{1,2})?%$/, message: '请输入百分%', trigger: 'blur' }
        ]
      }
    };
  },
  created() {
    this.listFollowType();
    console.log(this.$route);
  },
  methods: {
    add(info) {
      this.title = '添加跟单阶段';
      this.id = null;
      this.open = true;
      this.form = {
        stageName: '',
        auditUserId: '',
        sort: 0,
        remark: '',
        followTypeId: (info && info.id) || '',
        typeCategory:1

      };
      this.listFollowStatus()
      this.listSysUser();
    },
    edit(row) {
      this.title = '编辑跟单阶段';
      this.open = true;
      this.listSysUser();
      this.listFollowStatus();
      this.getDetail({ id: row.id });
    },
    cancel() {
      this.open = false;
    },
    listSysUser() {
      listUser()
        .then((res) => {
          this.userList = res.rows;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 获取跟单类型
    listFollowType() {
      listFollowType({
        pageSize: 9999,
        pageNum: 1,
        typeCategory:1
      })
        .then((res) => {
          this.followTypeList = res.rows;
        })
        .catch((err) => {
          console.log(err);
        });
    }
  }
};
</script>

<style lang="scss" scoped></style>